﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using BL;

namespace OpenLeuvenPortaal.Views
{
    public partial class DeveloperApps : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
            int devid = int.Parse(Request.QueryString["UserID"]);
            int i = 1;

            if (devid == 0)
            {
             
            }
            else{
                AppHandler appmger = new AppHandler();
                List<Applicaty> appslist = appmger.GetUserApps(devid);
                Table appstable = new Table();
                TableHeaderRow tbrow = new TableHeaderRow();
                TableHeaderCell thc1 = new TableHeaderCell();
                thc1.Text = "#";
                foreach (Applicaty a in appslist)
                {
                    TableRow newrow = new TableRow();
                    TableCell c1 = new TableCell();
                    TableCell c2 = new TableCell();
                    TableCell c3 = new TableCell();
                    TableCell c4 = new TableCell();

                    c1.Text = i.ToString();
                    i++;

                    HyperLink newlink = new HyperLink();
                    newlink.Text = a.AppNaam;
                    newlink.NavigateUrl = "http://" + a.AppLink;
                    
                    c2.Controls.Add(newlink);
                    
                    
                    c3.Text = a.AppStatus1.StatusNaam;

                    HyperLink newlink2 = new HyperLink();
                    newlink2.Text = a.AppNaam;
                    newlink2.NavigateUrl = "DeveloperAppsDetails.aspx?ID=" + a.AppID;
                    c4.Controls.Add(newlink2);

                    newrow.Cells.Add(c1);
                    newrow.Cells.Add(c2);
                    newrow.Cells.Add(c3);
                    newrow.Cells.Add(c4);

                    AppsTable.Rows.Add(newrow);

                }
                
            }
        }

        private void pg()
        {
        
            //int userid = new (int)Session["userid"];
            //dbopenleuvenDataContext db = new dbopenleuvenDataContext();
            //var result = from a in db.Applicaties where a.UserID == userid select a;
            //List<Model.Applicaty> MijnLijstperDeveloper = result.ToList();
            dbopenleuvenDataContext db = new dbopenleuvenDataContext();
            var result = from a in db.Applicaties select a;
            List<Model.Applicaty> mijnApplicaties = result.ToList();

            
            
            Int32 i; //create a integer variable
            foreach (Applicaty a in mijnApplicaties)
            {
                HyperLink hyperlink = new HyperLink();
                hyperlink.Text = Convert.ToString(a.AppLink);
                hyperlink.ID = Convert.ToString(a.AppID);
                hyperlink.NavigateUrl = "DeveloperAppsDetails.aspx?ID=" + a.AppID;
                //hyperlink.NavigateUrl = a.AppLink;
                //hyperlink.Attributes["src"]=(a.AppLink);
                PlaceHolderApplications.Controls.Add(hyperlink); // Adding the hyperlink in PlaceHolder
            }
        }

        void hyperlink_Command(object sender, CommandEventArgs e)
        {

            //Label1.Text = e.CommandName; // will display the which Linkbutton clicked
            //Response.Redirect(“LnkBtn.aspx?val=” + Label1.Text); // you can also use as QueryString to send values to another page
        }

        protected void BtnUpload_Click(object sender, EventArgs e)
        {
            Response.Redirect("AdminHomepage.aspx");
        }

        protected void BtnReqDel_Click(object sender, EventArgs e)
        {
            Response.Redirect("AdminHomepage.aspx");
        }

        protected void BtnComment_Click(object sender, EventArgs e)
        {
            Response.Redirect("AdminHomepage.aspx");
        }
    }
}